Skip to content

fix: coerce singleFile strings->bools so non-singleFile won't bundle deps#735

Merged
asyncapi-bot merged 1 commit intoasyncapi:masterfrom
michael-ball-ctct:issue734/singleFile_false_misbehaving
Jul 15, 2025
Merged

fix: coerce singleFile strings->bools so non-singleFile won't bundle deps#735
asyncapi-bot merged 1 commit intoasyncapi:masterfrom
michael-ball-ctct:issue734/singleFile_false_misbehaving

Conversation

@michael-ball-ctct
Copy link
Contributor

Description

Currently html-template parses the string 'false' as true because it is a non-empty string. This leads to the html file that is generated being created with its dependencies built in, when it should not.

By coercing this value to a boolean, this change ensures that only strings that match 'true' or true boolean values will match the singleFile behaviour, and otherwise stick to the default non-singleFile behaviour. Other strings (including 'false') will generate non-singleFile documentation.

This behaviour satisfies the TypeScript contract which states that the value of the singleFile optional param must be a string. It does not solve the behaviour that if AsyncAPI/generator is given a singleFile param of a false boolean it will generate a non-singleFile formatted index.html while failing to also generate the dependency files non-singleFiles refer to. This is because A) fixing this behaviour appears to be outside of the html-template repo and B) that's outside of the aforementioned expected types supported, as per the TypeScript definition.

Using the test repo I created for #734 and pointing the template towards this repo will show a fixed case for singleFileFalseString (but not singleFileFalseBoolean, as discussed above).

Related documentation
None, other than the code comment explaining the coercion - which can be removed/amended if not fitting with repo style. This change is ensuring behaviour matches existing TypeScript + written documentation.

Related issue(s)

Fixes #734

Test results

 PASS  test/helpers/all.test.js
 PASS  test/components/index.test.js
------------|---------|----------|---------|---------|-----------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s           
------------|---------|----------|---------|---------|-----------------------------
All files   |      70 |    66.66 |     100 |   70.88 |                             
 components |   76.47 |       50 |     100 |   76.47 |                             
  index.js  |   76.47 |       50 |     100 |   76.47 | 15,22,29,33                 
 helpers    |   68.25 |    73.33 |     100 |   69.35 |                             
  all.js    |   68.25 |    73.33 |     100 |   69.35 | 18,22,45-50,103-117,163-166 
------------|---------|----------|---------|---------|-----------------------------

Test Suites: 2 passed, 2 total
Tests:       13 passed, 13 total
Snapshots:   4 passed, 4 total
Time:        2.707 s
Ran all test suites.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@sonarqubecloud
Copy link

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks a lot!

@derberg
Copy link
Member

derberg commented Jul 15, 2025

/rtm

@asyncapi-bot asyncapi-bot merged commit fe4d8f2 into asyncapi:master Jul 15, 2025
20 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 3.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Inconsistent singleFile behaviour

3 participants

Comments